<?php

namespace app\admin\dao;

use app\common\model\MemberInvite;
use ShidianUtil\Thinkphp\Dao\DaoTrait;

/**
 * MemberInviteDao 数据访问对象
 * Class MemberInviteDao
 * @package app\dao
 * @method MemberInvite findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method MemberInvite insertActive(array $params, array $allow_field = [])
 * @method MemberInvite updateActive(MemberInvite $model, array $params, array $allow_field = [])
 * @method MemberInvite findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method MemberInvite updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(MemberInvite $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class MemberInviteDao
{
    use DaoTrait;

    /**
     * @var \app\common\model\MemberInvite
     */
    private $baseModel;

    /**
     * MemberInviteDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = MemberInvite::class;
    }

    /**
     * 插入邀请记录
     * @param int $memberId 邀请人
     * @param int $memberIdInvite 被邀请人
     * @param int $status 邀请关系，0停止 1开启 2未认证待激活
     * @return void
     */
    public function insert($memberId, $memberIdInvite, $status = 1)
    {

        if (!is_id($memberId) || !is_id($memberIdInvite) || $memberId == $memberIdInvite) {
            return;
        }

        $params = [
            'memberId' => $memberId,
            'memberIdInvite' => $memberIdInvite,
            'status' => $status,
        ];

        try {

            $this->insertActive($params);
        } catch (\Exception $exception) {

        }
    }
}
